﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Text;
using Windows.Globalization.Collation;

namespace JiveMessenger.Models
{
    public class VisualGroup:INotifyPropertyChanged
    {
        private IChatGroup _group;
        public IChatGroup Group
        {
            get { return _group; }
            set
            {
                if (_group != value)
                {
                    _group = value;
                    RaisePropertyChanged("Group");
                }
            }
        }

        private ObservableCollection<IContact> _contact;
        public ObservableCollection<IContact> Contacts
        {
            get { return _contact; }
            set
            {
                if (_contact != value)
                {
                    _contact = value;
                    RaisePropertyChanged("Contacts");
                }
            }
        }

        //public static List<JiveAlphabeticalGroup> CreateGroups(IEnumerable<IContact> source)
        //{
        //    // Get the letters representing each group for current language using CharacterGroupings class
        //    var characterGroupings = new CharacterGroupings();

        //    // Create dictionary for the letters and replace '...' with proper globe icon
        //    var keys = characterGroupings.Where(x => x.Label.Count() >= 1)
        //        .Select(x => x.Label)
        //        .ToDictionary(x => x);
        //    keys["..."] = "\uD83C\uDF10";
        //    // Create groups for each letters
        //    var groupDictionary = keys.Select(x => new JiveAlphabeticalGroup() { ID = x.Value, Name = x.Value })
        //        .ToDictionary(x => (string)x.ID);

        //    // Sort and group items into the groups based on the value returned by the selector
        //    var query = from item in source
        //                orderby item.PrettyName
        //                select item;

        //    foreach (var item in query)
        //    {
        //        var sortValue = item.PrettyName;
        //        groupDictionary[keys[characterGroupings.Lookup(sortValue.Take(1).ToString())]].Contacts.Add(item);
        //    }
        //    return groupDictionary.Select(x => x.Value).ToList();
        //}
        public VisualGroup(IChatGroup group)
        {
            this.Group = group;
        }
        public VisualGroup(IChatGroup group,ObservableCollection<IContact> contacts)
        {
            this.Group = group;
            this.Contacts = contacts;
        }
        protected void RaisePropertyChanged(string propertyName)
        {
            PropertyChangedEventHandler handler = PropertyChanged;
            if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
        }
        public event PropertyChangedEventHandler PropertyChanged;
    }
}
